﻿using bilibili下载.Interface;
using NLog;
using System;
using System.Linq;

namespace bilibili下载.Models
{
    public static class AnalysisFactory
    {
        private static readonly Logger logger = NLog.LogManager.GetCurrentClassLogger();

        public static bool Factory(string url, out IAnalysis aVs)
        {
            //Uri uri = new Uri("https://www.bilibili.com/video/BV1mJ411F7zG?p=4");
            logger.Debug("开始解析地址：{0}", url);
            if (Uri.TryCreate(url, UriKind.Absolute, out var uri))
            {
                if (uri.Host == "www.bilibili.com")
                {
                    var Type = uri.Segments.Last();
                    if (Type.StartsWith("BV"))
                    {
                        aVs = new BVAnalysis(Type);
                    }
                    else
                    {
                        logger.Debug("未知视频来源：{0},请确认正确后联系作者", url);
                        aVs = null;
                    }
                    return aVs != null;
                }
                else logger.Debug("连接域名：{0},不为哔哩哔哩", url);
            }
            else logger.Debug("地址：{0},解析失败", url);
            aVs = null;
            return false;
        }
    }
}